$(function() {

	$("#qiuZhiZheLoginBut").click(function() {
		// 点击求职者登录
		$("#qiuZhiZheLogin").show();// 求职者登录
		$("#zhaoPingZheLogin").hide();// 招聘者登录
		$("#qiuZhiZheZhaoHuiPwd").hide();// 求职者找回密码
		$("#zhaoPinZheZhaoHuiPwd").hide();// 招聘者找回密码
		$(".tab_active").animate({
			left : "0px"
		});
		$("#zhaoPingZheLoginBut").removeClass("active");
		$("#qiuZhiZheLoginBut").addClass("active");
	});

	$("#zhaoPingZheLoginBut").click(function() {
		// 点击招聘者登录
		$("#zhaoPingZheLogin").show();// 招聘者登录
		$("#qiuZhiZheLogin").hide();// 求职者登录
		$("#qiuZhiZheZhaoHuiPwd").hide();// 求职者找回密码
		$("#zhaoPinZheZhaoHuiPwd").hide();// 招聘者找回密码
		$(".tab_active").animate({
			left : "145px"
		});
		$("#qiuZhiZheLoginBut").removeClass("active");
		$("#zhaoPingZheLoginBut").addClass("active");
	});

	loadAlter();
	$("#alterBut").click(function() {
		$(".alterDiv").hide();
	});

	$("#qiuZhiZheZhaoHuiPwdBut").click(
			function() {
				// 求职者找回密码
				if (checkBasic_email() && checkBasic_phone()
						&& checkasic_card()) {
					var zhaoHuiPwdForm = $("#qiuZhiZheZhaoHuiPwdForm")
							.serialize();
					utilAjax("/basic_information/retrievePassword",
							zhaoHuiPwdForm, "post", function(data) {
								if (data.map != null) {
									$("#alterContent").html(
											"找回成功<br>密码："
													+ data.map.basic_password);
									loadAlter();
								} else {
									$("#alterContent").html(
											"找回失败，请检查手机、邮箱、身份证是否输入错误");
									loadAlter();
								}
							});
					return true;
				}
				return false;

			});

	$("#zhaoPinZheQueryPwd").click(function() {
		// 招聘者找回密码
		var zhaoHuiPwdForm = $("#zhaoPinZheZhaoHuiPwdForm").serialize();
		if(checkLookPwd()){
			utilAjax("/recruiter/queryPwd", zhaoHuiPwdForm, "post", function(data) {
					if (data != "") {
						$("#alterContent").html("找回成功<br>密码：" + data.recruiter_ps);
						loadAlter();
					} else {
						$("#alterContent").html("找回失败，请检查手机、邮箱、身份证是否输入错误");
						loadAlter();
					}
			});
			return true;
		}
		return false;
		
	});
});

function showQiuZhiZheZhaoHuiPwd() {
	// 求职者登录 点击找回密码
	$("#qiuZhiZheLogin").hide();// 求职者登录
	$("#qiuZhiZheZhaoHuiPwd").show();// 求职者找回密码
}
function backQiuZhiZheZhaoHuiPwd() {
	// 求职者登录 找回密码 点击返回
	$("#qiuZhiZheLogin").show();// 求职者登录
	$("#qiuZhiZheZhaoHuiPwd").hide();// 求职者找回密码
}
function showZhaoPinZheZhaoHuiPwd() {
	// 招聘者登录 点击找回密码
	$("#zhaoPingZheLogin").hide();// 招聘者登录
	$("#zhaoPinZheZhaoHuiPwd").show();// 招聘者找回密码
}
function backZhaoPinZheZhaoHuiPwd() {
	// 招聘者者登录 找回密码 点击返回
	$("#zhaoPingZheLogin").show();// 招聘者登录
	$("#zhaoPinZheZhaoHuiPwd").hide();// 招聘者找回密码
}

function loadAlter() {
	var alterCon = $("#alterContent").text();
	if (alterCon != "") {
		$(".alterDiv").show();
		var interval = setInterval(function() {
			$(".alterDiv").hide();
			$("#alterContent").text("");
			clearInterval(interval);
		}, 3000);
	}
	$("#alterBut").click(function() {
		$(".alterDiv").hide();
	});
}

function utilAjax(url, data, type, success) {
	$.ajax({
		url : url,
		data : data,
		dataType : 'json',
		type : type,
		success : success,
		error : function() {
		}
	});
}

function checkPhone() {
	// 检查手机号码
	var basic_phone = $("#basic_phone").val();
	var reg_tel = /^1(3|4|5|6|7|8|9)\d{9}$/;// 手机格式的正则
	// 3.判断
	var flag = reg_tel.test(basic_phone);
	if (flag) {
		$("#basic_phone").css("border", "");
	} else {
		$("#basic_phone").css("border", "1px solid red");
		$("#alterContent").html("请检查手机格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}
function checkPassword() {
	// 检查密码
	var basic_password = $("#basic_password").val();
	if (basic_password.length < 6 || basic_password.length > 20) {
		// 密码非法,加一个红色边框
		$("#basic_password").css("border", "1px solid red");
		$("#alterContent").html("密码长度不能小于6位，且不能大于20位！！！");
		loadAlter();
		return false;
	} else {
		// 密码合法
		$("#basic_password").css("border", "");
		return true;
	}
}

function checkQiuZhiZheLogin() {
	if (checkPhone() && checkPassword()) {
		return true;
	}
	return false;
}

function checkBasic_email() {
	var basic_email = $("#basic_email2").val();
	// 2.定义正则 itcast@163.com
	var reg_tel = /^\w+@\w+\.\w+$/;
	var flag = reg_tel.test(basic_email);
	if (flag) {
		$("#basic_email2").css("border", "");
	} else {
		$("#basic_email2").css("border", "1px solid red");
		$("#alterContent").html("请检查邮箱格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}
function checkBasic_phone() {
	var basic_phone = $("#basic_phone2").val();
	var reg_tel = /^1(3|4|5|6|7|8|9)\d{9}$/;
	var flag = reg_tel.test(basic_phone);
	if (flag) {
		$("#basic_phone2").css("border", "");
	} else {
		$("#basic_phone2").css("border", "1px solid red");
		$("#alterContent").html("请检查手机格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}
function checkasic_card() {
	var basic_card = $("#basic_card2").val();
	var reg_tel = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
	var flag = reg_tel.test(basic_card);
	if (flag) {
		$("#basic_card2").css("border", "");
	} else {
		$("#basic_card2").css("border", "1px solid red");
		$("#alterContent").html("请检查身份证格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}

function checkZhaoPingZheLogin() {
	// 检查招聘者登录
	if (checkLoginRecruiter_phone() && checkLoginRecruiter_ps()) {
		return true;
	}
	return false;
}
function checkLoginRecruiter_phone() {
	// 招聘者登录 输入手机号
	var loginRecruiter_phone = $("#loginRecruiter_phone").val();
	var reg_tel = /^1(3|4|5|6|7|8|9)\d{9}$/;
	var flag = reg_tel.test(loginRecruiter_phone);
	if (flag) {
		$("#loginRecruiter_phone").css("border", "");
	} else {
		$("#loginRecruiter_phone").css("border", "1px solid red");
		$("#alterContent").html("请检查手机格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}

function checkLoginRecruiter_ps() {
	// 招聘者登录 输入密码
	var loginRecruiter_ps = $("#loginRecruiter_ps").val();

	if (loginRecruiter_ps.length < 6 || loginRecruiter_ps.length > 20) {
		// 密码非法,加一个红色边框
		$("#loginRecruiter_ps").css("border", "1px solid red");
		$("#alterContent").html("密码长度不能小于6位，且不能大于20位！！！");
		loadAlter();
		return false;
	} else {
		// 密码合法
		$("#loginRecruiter_ps").css("border", "");
		return true;
	}
}

function checkLookRecruiter_email(){
	//招聘者找回密码  邮箱
	var lookRecruiter_email = $("#lookRecruiter_email").val();
	// 2.定义正则 itcast@163.com
	var reg_tel = /^\w+@\w+\.\w+$/;
	var flag = reg_tel.test(lookRecruiter_email);
	if (flag) {
		$("#lookRecruiter_email").css("border", "");
	} else {
		$("#lookRecruiter_email").css("border", "1px solid red");
		$("#alterContent").html("请检查邮箱格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}
function checkLookRecruiter_phone(){
	//招聘者找回密码   手机号
	var lookRecruiter_phone = $("#lookRecruiter_phone").val();
	var reg_tel = /^1(3|4|5|6|7|8|9)\d{9}$/;
	var flag = reg_tel.test(lookRecruiter_phone);
	if (flag) {
		$("#lookRecruiter_phone").css("border", "");
	} else {
		$("#lookRecruiter_phone").css("border", "1px solid red");
		$("#alterContent").html("请检查手机格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}
function checkLookRecruiter_card(){
	//招聘者找回密码   身份证号码
	var lookRecruiter_card = $("#lookRecruiter_card").val();
	var reg_tel = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
	var flag = reg_tel.test(lookRecruiter_card);
	if (flag) {
		$("#lookRecruiter_card").css("border", "");
	} else {
		$("#lookRecruiter_card").css("border", "1px solid red");
		$("#alterContent").html("请检查身份证格式是否正确！！！");
		loadAlter();
	}
	// 4.返回校验是否通过
	return flag;
}

function checkLookPwd(){
	if(checkLookRecruiter_email() && checkLookRecruiter_phone() && checkLookRecruiter_card()){
		return true;
	}
	return false;
}
